package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.model.SkuInfo;
import com.atguigu.gmall.product.service.SkuManageService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author XIN
 * 2023/4/21
 */
@RestController
@RequestMapping("/admin/product")
public class SkuManageController {
	@Autowired
	private SkuManageService skuManageService;
	/**
	 * 保存商品SKU信息
	 * @return
	 */
	@PostMapping("/saveSkuInfo")
	public Result saveSkuInfo(@RequestBody SkuInfo s) {
		skuManageService.saveSkuInfo(s);
		return Result.ok();
	}
	
	/**
	 * 根据分类ID分页查询商品SKU列表
	 * @param page
	 * @param limit
	 * @param category3Id
	 * @return
	 */
	@GetMapping("/list/{page}/{limit}")
	public Result list(@PathVariable Long page, @PathVariable Long limit,@RequestParam("category3Id")Long category3Id) {
		IPage<SkuInfo> iPage = new Page<>(page,limit);
		iPage = skuManageService.list(iPage,category3Id);
		return Result.ok(iPage);
	}
	
	/**
	 * 上架
	 * @param skuId
	 * @return
	 */
	@GetMapping("/onSale/{skuId}")
	public Result onSale(@PathVariable Long skuId) {
		skuManageService.onSale(skuId);
		return Result.ok();
	}
	
	/**
	 * 下架
	 * @param skuId
	 * @return
	 */
	@GetMapping("/cancelSale/{skuId}")
	public Result cancelSale(@PathVariable Long skuId) {
		skuManageService.concelSale(skuId);
		return Result.ok();
	}
}
